#! /bin/sh -eu

MVN_SETTING=
JAVA_WORK_DIR=$(pwd)
WEB_DIR=$(pwd)/web/barn-ng

help(){
        echo "--maven-setting set your maven settings.xml"
        echo "--java-dir set your java directory"
        echo "--web-dir set your web directory"
	echo "-h/--help show this help"
        exit 0
}
while [ $# -gt 0 ]; do
 case "$1" in
        --maven-setting)
        MVN_SETTING="$2"
        shift
        ;;
        --java-dir)
        JAVA_WORK_DIR="$2"
        shift
        ;;
        --web-dir)
        WEB_DIR="$2"
        shift
        ;;
        -h|--help)
        help
        ;;
        *)
                echo "unknow argumanet '$1'"
    esac
    shift
done

java_package(){
	echo $MVN_SETTING
        cd $JAVA_WORK_DIR
        echo "java is packaging, work directory is $(pwd)"
        echo "MVN_SETTING is $MVN_SETTING"
        MVN_OPS=
        ## TODO 这里为什么一直为真？
        if [ -n "$MVN_SETTING" ];then
                cp $MVN_SETTING /opt/maven/conf/settings.xml
		echo "your setting file coped"
        else
                echo "use default maven setting file"
        fi
        CMD="mvn $MVN_OPS package"
        echo "mvn command is $CMD"
        $CMD
}
java_package
